package cc.facesign.admin.utils;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class IOUtils {

    /**
     * File
     */
    public static Map<String, MultipartFile> getFiles(List<MultipartFile> pics)  {

        Map<String, MultipartFile> map = new HashMap<>();
        for (MultipartFile e : pics) {
            String name = e.getOriginalFilename();
            map.put(name, e);
        }

        return map;
    }

    /**
     * byte[] 转 object
     */

    public static Object tranObject(byte[] bytes) {
        ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
        ObjectInputStream oin = null;
        try {
            oin = new ObjectInputStream(bin);
            Object o = (T)oin.readObject();

            return o;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }

}
